package com.haidong.myfile.Listener;

import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class MyKeyListen implements KeyListener {
    //更改键盘的监听器,保持输入光标不被方向键移动
    @Override
    public void keyTyped(KeyEvent e) {
        if(e.getKeyCode()>=37 && e.getKeyCode()<=40){
            TextArea field = (TextArea) e.getSource();
            field.setCaretPosition(field.getText().length());
        }
    }
    @Override
    public void keyPressed(KeyEvent e) {
        if(e.getKeyCode()>=37 && e.getKeyCode()<=40){
            TextArea field = (TextArea) e.getSource();
            field.setCaretPosition(field.getText().length());
        }
    }
    @Override
    public void keyReleased(KeyEvent e) {
        if(e.getKeyCode()>=37 && e.getKeyCode()<=40){
            TextArea field = (TextArea) e.getSource();
            field.setCaretPosition(field.getText().length());
        }
    }
}